home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17049 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: bnc.net!news
  2. From: Alexander.Glaeser@Bonn.Netsurf.De (Alex Glaeser)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: READING FROM A TEXTFILE
  5. Date: Sat, 13 Apr 1996 07:36:53 GMT
  6. Organization: Bonner Network Consulting
  7. Message-ID: <316f5587.1505339@news.bonn.netsurf.de>
  8. References: <Pine.SUN.3.90.960412122731.1477A-100000@dew.cs.odu.edu>
  9. NNTP-Posting-Host: angra.bonn.netsurf.de
  10. X-Newsreader: Forte Agent .99d/32.182
  11.  
  12.  
  13.  
  14. Hi Cleveland !!
  15.  
  16. >    I have had trouble reading from a textfile.  I am trying to read 
  17. >a textfile into a C++ struct.  This is the struct
  18. >
  19. >#include <iostream.h>
  20. >#include <fstream.h>
  21. >
  22. >
  23. > struct students {
  24. >char firstname[20];
  25. >char middle_initial;
  26. >char lastname[20];
  27. >char address1[40];
  28. >char address2[30];
  29. >char phone_number[7];
  30. >char email[50];
  31. >char dept[16];
  32. >char edu_level[9];
  33. >};
  34. >
  35. >
  36. >The textfile has contains char firstname down to edu_level --- each char 
  37. >string is one line in the file.
  38. >
  39. >How can I read this struct from the textfile?
  40.  
  41. You have to fill it up step by step.
  42. Just use the function called "filename.getline(*string[],positions)".
  43. In this case "filename" is the internal name of the file you want to
  44. read from. "*string[]" is the array you want to read in and
  45. "positions" is the maximum number of characters you want to read from
  46. this line. Getline() will return a reference to *string[].
  47.  
  48. Hope this will help.
  49.  
  50. Later
  51.         ALEX
  52.  
  53. __________________________________________________________________
  54.   Think Positive !!!         ## Phone'n'Fax  ++49 2241 330773 ##
  55.